<%--                                                                       --%>
<%-- Copyright (c) 2001-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>
<%--                                                                       --%>

<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> 
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<jsp:useBean id="groupEditView" scope="request" type="com.broadvision.web.util.ViewDynaBean"/> 

<script language="JavaScript">
function confirmDeleteGroup()
{
   if (confirm('<bean:message key="cs.confirm.delete.group"/>'))
   {
      location='<html:rewrite page="/cs/groupDelete.do" name="micrositeNaviInfoView" property="urlParams"/>';
   }
}

function onClickCancel() {
  location='<html:rewrite page="/cs/groupList.do" name="micrositeNaviInfoView" property="urlParams"/>';
}

//
// Trims leading blanks.
//
function stringLeftTrim(s)
{
   return s.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function stringRightTrim(s)
{
   return s.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function stringTrim(s)
{
   return stringRightTrim(stringLeftTrim(s));
}

//
// Validate the user's entries.
//
function validateForm(theForm)
{
   var contactGroup = <bean:write name="groupEditView" property="contactGroup" />;
   var ownerGroup = <bean:write  name="groupEditView" property="ownerGroup" />;
   var participantGroup = <bean:write  name="groupEditView" property="participantGroup" />;
   if (contactGroup) {
     theForm.submit();
   } else if (participantGroup) {
     theForm.submit();
   } else if (ownerGroup && validateOwnerGroup(theForm)) {
     theForm.submit();
   } else if (validateRegularGroup(theForm)) {
     theForm.submit();
   }
}

function validateOwnerGroup(theForm) {
  //
  // check at least one participant is designated as a owner.
  //
  var len = theForm.userMemberIds.length;

  if (len) { //more than one.
    for ( var i=0; i<len; i++ ) {
      if (theForm.userMemberIds[i].checked == true) {
        return true;
      }
    }
  } else {
    if (theForm.userMemberIds.checked == true) {
      return true;
    }
  }

  //There is no one checked.
  alert('<bean:message key="cs.error.one.participant.owner"/>');
  return false;
}

function validateRegularGroup(theForm) {
   var newFriendlyName = stringTrim(theForm.newFriendlyName.value);

   if (newFriendlyName == "")
   {
      alert('<bean:message key="cs.error.group.name"/>');
      return false;
   }

   var groupDesc = stringTrim(theForm.description.value);
   if (groupDesc.length > 2000) 
   {
      alert('<bean:message key="cs.error.group.description.num"/>');
      return false;
   }

   theForm.newFriendlyName.value = newFriendlyName;
   theForm.description.value = groupDesc;
   return true;
}

</script>

<!-- Zone 5 starts here.  -->
      
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    <!--  BEGIN form { group } ----------------------------- -->
    
    <html:form action="/cs/groupSave.do" method="post" onsubmit="return false;">
      <bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>  
    
    <!--start microsite logo and name here-->
      <div class="pageTitle">
        <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
      </div> 
    <!--end microsite logo and name here-->
    
    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
        <bean:write name="groupEditView" property="pageTitle" />
      </span>
      
      <span class="right">
	&nbsp;
      </span>
    </div> 
    <!--end title bar here--> 
     
    <div class="blockWrap">
     
    <!-- start Page Instructions -->
    <div class="pageInstructions">
      <logic:greaterThan name="csGroupEditForm" property="groupId" value="0">
        <bean:message key="cs.group.edit.old.notes"/>
      </logic:greaterThan>
      <logic:equal name="csGroupEditForm" property="groupId" value="0">
        <bean:message key="cs.group.edit.new.notes"/>
      </logic:equal>
    </div>
    <!-- End Page Instructions -->
    
    <!--start main content area here-->
    <table class="labelForm" width="100%" border="0" cellspacing="0" 
           cellpadding="0" summary="Edit Group">
      <tr> 
        <td nowrap width="20%" class="label"><bean:message key="cs.name"/>*:<br>
        </td>
        <td width="80%" class="labelField" nowrap>
          <logic:notEqual name="groupEditView" property="systemGroup" value="true">
            <html:text property="newFriendlyName" size="20" maxlength="80"/>
          </logic:notEqual> 
          <logic:equal name="groupEditView" property="systemGroup" value="true">
            <bean:write name="groupEditView" property="persistentFriendlyName"/>
          </logic:equal> 
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label"> 
          <bean:message key="cs.description"/>:  
        </td>
        <td width="80%" class="labelField" nowrap>
          <logic:notEqual name="groupEditView" property="systemGroup" value="true">
            <html:textarea property="description" cols="30" rows="5"/>
          </logic:notEqual>
          <logic:equal name="groupEditView" property="systemGroup" value="true">
            <html:hidden property="description" />
            <bean:write name="csGroupEditForm" property="description"/>
          </logic:equal>
        </td>
      </tr>
      <tr> 
        <td nowrap width="20%" class="label" rowspan="4" valign="top">
          <bean:message key="cs.document.access.role"/>*:
        </td>
        <td width="80%" class="labelField" nowrap> 
          <html:radio property="documentAccessRole" value="3"/>
          <bean:message key="cs.document.editor"/>
        </td>
      </tr>
      <tr> 
        <td width="80%" class="labelField" nowrap> 
          <html:radio property="documentAccessRole" value="2"/>
          <bean:message key="cs.document.author"/>
        </td>
      </tr>
      <tr> 
        <td width="80%" class="labelField" nowrap> 
          <html:radio property="documentAccessRole" value="1"/>
          <bean:message key="cs.document.reader"/>
        </td>
      </tr>
      <tr> 
        <td width="80%" class="labelField" nowrap> 
          <html:radio property="documentAccessRole" value="0"/>
          <bean:message key="cs.document.no.access"/>
        </td>
      </tr>
      
      <!-- start of user members section -->
      <logic:equal name="groupEditView" property="participantGroup" value="true"> 
        <tr> 
          <td nowrap width="20%" class="label">
            <bean:message key="cs.group.select.user.members"/>:
          </td>
          <td width="80%" class="labelField" nowrap>
            <c:choose>
              <c:when test="${micrositeNaviInfoView.map.isMicrosite}">
                <bean:message key="cs.group.public.members.microsite"/>
              </c:when>
              <c:otherwise>
                <bean:message key="cs.group.public.members"/>
              </c:otherwise>
            </c:choose>
          </td>
        </tr>
      </logic:equal>
      <logic:notEqual name="groupEditView" property="participantGroup" value="true">
        <%-- This is NOT a participant group. --%>
         
        <%-- There are user members in the group. --%>
        <logic:iterate id="oneMember" name="groupEditView" property="userMemberCandidates" indexId="index">
          <tr>
            <logic:equal name="index" value="0">
              <td nowrap width="20%" class="label">
                <bean:message key="cs.group.select.user.members"/>:
              </td>
            </logic:equal>
            <logic:notEqual name="index" value="0">
              <td nowrap width="20%" class="label">&nbsp;</td>
            </logic:notEqual>

            <td width="80%" class="labelField" nowrap>
              <html:multibox property="userMemberIds">
                <bean:write name="oneMember" property="value" />
              </html:multibox>
              <bean:write name="oneMember" property="label" />
            </td>
          </tr> 
        </logic:iterate>
      </logic:notEqual> <%-- End of: not participant group. --%>
    <!-- end of user members secion -->    

    <!-- start of member groups section -->
    <logic:equal name="groupEditView" property="showMemberGroups" value="true">
      <logic:equal name="groupEditView" property="participantGroup" value="true"> 
        <tr> 
          <td nowrap width="20%" class="label">
            <bean:message key="cs.group.select.member.groups"/>:
          </td>
          <td width="80%" class="labelField" nowrap>
            <c:choose>
              <c:when test="${micrositeNaviInfoView.map.isMicrosite}">
                <bean:message key="cs.group.public.members.microsite"/>
              </c:when>
              <c:otherwise>
                <bean:message key="cs.group.public.members"/>
              </c:otherwise>
            </c:choose>
          </td>
        </tr>
      </logic:equal>
      <logic:notEqual name="groupEditView" property="participantGroup" value="true">
        <%-- This is NOT a participant group. --%>
         
        <%-- There are member groups in the group. --%>
        <logic:iterate id="oneMember" name="groupEditView" property="memberGroupCandidates" indexId="index">
          <tr>
            <logic:equal name="index" value="0">
              <td nowrap width="20%" class="label">
                <bean:message key="cs.group.select.member.groups"/>:
              </td>
            </logic:equal>
            <logic:notEqual name="index" value="0">
              <td nowrap width="20%" class="label">&nbsp;</td>
            </logic:notEqual>

            <td width="80%" class="labelField" nowrap>
              <html:multibox property="memberGroupNames">
                <bean:write name="oneMember" property="value" />
              </html:multibox>
              <bean:write name="oneMember" property="label" />
            </td>
          </tr> 
        </logic:iterate>
      </logic:notEqual> <%-- End of: not participant group. --%>
    </logic:equal>
    <!-- end of member groups secion -->    

    </table>
    <!--end main content area here-->

    <!--start cancel, reset, save bar area here-->

    <div class="pageButtonWrap" align="right">
      <html:reset styleClass="pageButton" property="resetBtn" titleKey="button.reset">
        <bean:message key="button.reset"/>
      </html:reset>
	&nbsp;&nbsp;
      <html:button styleClass="pageButton" property="cancelBtn" 
                 titleKey="button.cancel" onclick="onClickCancel()">
        <bean:message key="button.cancel"/>
      </html:button>
                 
      <html:submit styleClass="pageButton" property="saveBtn" 
          titleKey="button.save" onclick="return validateForm(this.form)">
        <bean:message key="button.save"/>
      </html:submit>
    </div>
 
    <!--end cancel, reset, save bar area here-->
  </html:form>
    </div>
    
  </td>
  </tr>
</table>
<!--end zone 5 content here -->
